home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / ccwindow.c next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  4.8 KB  |  159 lines

  1. /*
  2. #    Create_Window . c
  3. %
  4. %    extracted from x11_stuff.c
  5. */
  6.  
  7. #include "panel.h"
  8.  
  9. static    Pixel    black_pixel, white_pixel;    /* for GC only */
  10.  
  11. #define    SelectedMask    ExposureMask | StructureNotifyMask
  12.  
  13.  
  14. void    /* must start after colormap allocated to get correct GC color    */
  15. create_windows(img, window_geometry, stingy)
  16. register image_information *img;
  17. char    *window_geometry;
  18. {
  19. static XClassHint    class_hint = {"getx", "tuner"};
  20. char        default_geometry[30];
  21. int        width, height, x, y, icn_alloc = False;
  22. XSizeHints    size_hints;
  23. unsigned int    mask;
  24. unsigned long    gc_mask, xswa_mask;
  25. XGCValues    gc_values;
  26. XWMHints    wm_hints;
  27. XSetWindowAttributes xswa;
  28. Boolean    new_window = !(img->window | img->icn_window),
  29.     new_pixmaps = ((img->pixmap == NULL || img->icn_pixmap == NULL ||
  30.         img->mag_pixmap == NULL) && !img->pixmap_failed && !stingy);
  31.  
  32.     if (!img->window) {
  33.     sprintf(default_geometry, "=%dx%d", img->w, img->h);
  34.     mask = XGeometry(Dpy, Screen, window_geometry, default_geometry,
  35.              IMAGE_BORDERWIDTH, 1, 1, 0, 0,
  36.              &x, &y, &width, &height);
  37.  
  38.     size_hints.flags = 0;
  39.  
  40.     if (mask & (XValue | YValue)) {
  41.         size_hints.flags |= USPosition;
  42.         size_hints.x = x;
  43.         size_hints.y = y;
  44.     } else {
  45.         size_hints.flags |= PPosition;
  46.         size_hints.x = x = (DisplayWidth(Dpy, Screen) - width) >> 1;
  47.         size_hints.y = y = (DisplayHeight(Dpy, Screen) - height) >> 1;
  48.     }
  49.  
  50.     if (mask & (WidthValue | HeightValue)) {
  51.         size_hints.flags |=    USSize;
  52.         size_hints.width = width;
  53.         size_hints.height = height;
  54.     }
  55.     size_hints.flags |= PMaxSize;
  56.     size_hints.max_width = MAX(MIN(DisplayWidth(Dpy, Screen), (width+16)), 512);
  57.     size_hints.max_height = MAX(MIN(DisplayHeight(Dpy, Screen), (height+16)), 256);
  58.  
  59.     wm_hints.flags = InputHint;
  60.     wm_hints.input = True;
  61.  
  62.     DEBUGMESSAGE("window = (%dx%d) %dW x %dH\n", x, y, width, height);
  63.  
  64.     if (img->colormap==DefaultColormap(Dpy, Screen))
  65.         black_pixel = BlackPixel(Dpy, Screen),
  66.         white_pixel = WhitePixel(Dpy, Screen);
  67.     else    black_pixel = GetGray(Dpy, img->colormap, img->entries, 0),
  68.         white_pixel = GetGray(Dpy, img->colormap, img->entries, 248);
  69.  
  70.     xswa_mask = CWBackPixel | CWEventMask | CWBorderPixel;
  71.     xswa.background_pixel = black_pixel;
  72.     xswa.border_pixel = white_pixel;
  73.     xswa.event_mask = EnterWindowMask | KeyPressMask | PointerMotionMask
  74.             | ButtonAction | SelectedMask;
  75.     if (img->colormap) {
  76.         xswa.colormap = img->colormap;
  77.         xswa_mask |= CWColormap;
  78.     }
  79.  
  80.     img->frame = img->window = XCreateWindow(Dpy, Root_window, x, y,
  81.             width, height, IMAGE_BORDERWIDTH, img->dpy_depth,
  82.             InputOutput, img->dpy_visual, xswa_mask, &xswa);
  83.  
  84.     XSetNormalHints(Dpy, img->frame, &size_hints);
  85.     XSetClassHint(Dpy, img->frame, &class_hint);
  86.     XSetWMHints(Dpy, img->frame, &wm_hints);
  87.     XSetIconName(Dpy, img->frame, img->title);
  88.     img->event++;    /* Make image and icon windows of the right size. */
  89.     MaximumWindowSize(img, xswa, xswa_mask, img->dpy_depth);
  90.     }
  91.     XStoreName(Dpy, img->frame, img->title);
  92.  
  93.     if (!img->pixmap && new_pixmaps)
  94.     img->pixmap = XCreatePixmap(Dpy, img->window, img->w, img->h,
  95.                     img->dpy_depth);
  96.     img->refresh_pixmap = img->pixmap;
  97.  
  98.     if (!img->icn_window) {
  99.     xswa.event_mask = SelectedMask;
  100.     xswa_mask = CWEventMask;
  101.  
  102.     if (img->colormap) {
  103.         xswa.colormap = img->colormap;
  104.         xswa_mask |= CWColormap;
  105.     }
  106.  
  107.     img->icn_window = XCreateWindow(Dpy, Root_window, 0, 0,
  108.              img->icn_w, img->icn_h, 0, img->dpy_depth,
  109.              InputOutput,img->dpy_visual, xswa_mask, &xswa);
  110.  
  111.     size_hints.flags = PMinSize | PMaxSize;
  112.     size_hints.min_width = img->icn_w;
  113.     size_hints.max_width = img->icn_w;
  114.     size_hints.min_height = img->icn_h;
  115.     size_hints.max_height = img->icn_h;
  116.  
  117.     XSetNormalHints(Dpy, img->icn_window, &size_hints);
  118.     XStoreName(Dpy, img->icn_window, img->title);
  119.     XSelectInput(Dpy, img->icn_window, SelectedMask);
  120.     }
  121.  
  122.     if (!img->gc) {
  123.     gc_mask = 0;
  124.     gc_values.function = GXcopy;        gc_mask |= GCFunction;
  125.     gc_values.plane_mask = AllPlanes;    gc_mask |= GCPlaneMask;
  126.     gc_values.foreground = white_pixel;    gc_mask |= GCForeground;
  127.     gc_values.background = black_pixel;    gc_mask |= GCBackground;
  128.  
  129.     img->gc = XCreateGC(Dpy, img->window, gc_mask, &gc_values);
  130.     }
  131.  
  132.     if (!img->icn_pixmap) {
  133.     img->icn_pixmap = XCreatePixmap(Dpy, img->icn_window, img->icn_w,
  134.                     img->icn_h, img->dpy_depth);
  135.     img->icn_gc = XCreateGC(Dpy, img->icn_window, gc_mask, &gc_values);
  136.     icn_alloc = True;
  137.     }
  138.  
  139.     if (new_pixmaps || icn_alloc)
  140.     check_pixmap_allocation(img);
  141.  
  142.     if (new_window) {
  143.     if (img->icn_pixmap && img->icn_window) {
  144.         wm_hints.flags = (StateHint | IconPixmapHint | IconMaskHint |
  145.                 IconWindowHint);
  146.         wm_hints.initial_state = NormalState;
  147.         wm_hints.icon_pixmap = img->icn_pixmap;
  148.         wm_hints.icon_window = img->icn_window;
  149.         wm_hints.icon_mask = img->icn_pixmap;
  150.  
  151.         XSetWMHints(Dpy, img->window, &wm_hints);
  152.     }
  153.  
  154.     SetFontGetSize(img, "8x13");
  155.     XSetWindowBackgroundPixmap(img->dpy, img->icn_window, img->icn_pixmap);
  156.     get_cursors(img->window);
  157.     }
  158. }
  159.